﻿package mortal.game.view.lookPlayerInfo.view
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import baseEngine.system.*;
    import com.gengine.core.frame.*;
    import com.gengine.global.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.medal.*;
    import mortal.game.view.medal.view.*;
    import mortal.game.view.palyer.item.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.platform.platformTencent.*;

    public class LookPlayerModelPanel extends GSprite
    {
        private var _frameTimer:FrameTimer;
        private var _guildTxt:GTextFiled;
        private var _playerTitle:GTextFiled;
        private var _levelAndNameAndCarrar:GTextFiled;
        protected var _equipPanel:LookPlayerEquipPark;
        private var _leftBtn:GLoadedButton;
        private var _rightBtn:GLoadedButton;
        private var _roleModelPlayer:RoleModelPlayer;
        private var _vipIcon:GImageBitmap;
        private var _bg:GImageBitmap;
        private var _signatureTextBox:TextBox;
        private var _signatureText:GTextInput;
        private var _medalPanel:MedalBigIcon;
        private var _qqSpr:GSprite;
        private var _qqIcon:GImageBitmap;
        private var _halidomSp:LookPlayerHalidomPanel;
        protected var _changeBtn:GLoadingButton;
        protected var _changeBtn2:GLoadingButton;
        protected var _window:Window;
        protected var _rect3d:Rect3DObject;
        private var _3dRotationSp:GSprite;
        private var _3dRotationBm:GBitmap;
        private var _startX:Number;
        private var _endX:Number;
        private var turnValue:int;
        private var _haliShow:Boolean = false;
        private var _sLookPlayerInfo:SLookPlayerInfo;
        private var _img2d:Img2D;

        public function LookPlayerModelPanel(param1:Window)
        {
            this._window = param1;
            return;
        }// end function

        public function set window(param1:Window) : void
        {
            this._window = param1;
            this._3dRotationSp = UICompomentPool.getUICompoment(GSprite);
            this._3dRotationSp.x = 5;
            this._3dRotationSp.y = 38;
            this._3dRotationSp.mouseEnabled = true;
            this._3dRotationBm = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._3dRotationBm.width = 500;
            this._3dRotationBm.height = 480;
            this._3dRotationSp.addChild(this._3dRotationBm);
            this._bg = UIFactory.gImageBitmap("", 11, 38, null, this.add2d);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountTitleBg, 13, 43, this._window.contentTopOf3DSprite));
            this._window.contentTopOf3DSprite.addChild(this._3dRotationSp);
            this._vipIcon = UIFactory.gImageBitmap("", 430, 50, this._window.contentTopOf3DSprite);
            var _loc_2:* = GlobalStyle.textFormatBai.center();
            _loc_2.size = 13;
            _loc_2.align = AlignMode.CENTER;
            this._guildTxt = UIFactory.gTextField("", 160, 81, 200, 30, this._window.contentTopOf3DSprite, _loc_2, true);
            var _loc_4:Boolean = false;
            this._guildTxt.mouseEnabled = false;
            this._guildTxt.selectable = _loc_4;
            this._playerTitle = UIFactory.gTextField("", 135, 106, 200, 30, this._window.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.center(), true);
            _loc_2.size = 13;
            this._levelAndNameAndCarrar = UIFactory.gTextField("", 157, 50, 200, 30, this._window.contentTopOf3DSprite, _loc_2, true);
            if (PlatformConst.isQQ() && PlatformTencentUtil.isBlueEnter())
            {
                this._qqSpr = UICompomentPool.getUICompoment(GSprite);
                this._qqSpr.move(167, 50);
                this._window.contentTopOf3DSprite.addChild(this._qqSpr);
                this._qqIcon = UIFactory.gImageBitmap("", 0, 0, this._qqSpr);
                this._qqSpr.mouseChildren = false;
                this._qqSpr.mouseEnabled = true;
                this._qqSpr.buttonMode = true;
            }
            this._leftBtn = UIFactory.gLoadedButton(ImagesConst.TurnLeft2_upSkin, 330, 483, 40, 36, this._window.contentTopOf3DSprite);
            this._leftBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onClickTurnBtn);
            this._rightBtn = UIFactory.gLoadedButton(ImagesConst.TurnRight2_upSkin, 141, 483, 40, 36, this._window.contentTopOf3DSprite);
            this._rightBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onClickTurnBtn);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopTurning);
            this._equipPanel = UICompomentPool.getUICompoment(LookPlayerEquipPark);
            this._equipPanel.createDisposedChildren();
            this._equipPanel.x = 131;
            this._equipPanel.y = 90;
            this._window.contentTopOf3DSprite.addChild(this._equipPanel);
            this._signatureTextBox = this.createTextBox(1);
            this._signatureTextBox.textField.autoSize = AlignMode.LEFT;
            this._signatureTextBox.x = 23;
            this._signatureTextBox.y = 557;
            this._signatureTextBox.bgWidth = 445;
            this._signatureTextBox.bgHeight = 25;
            this._signatureTextBox.htmlText = "<font color=\'#f8eacd\'>" + Language.getString(35332) + "</font>";
            this._signatureText = UIFactory.gTextInput(85, 556, 445, 25, this._window.contentTopOf3DSprite, null);
            this._signatureText.editable = false;
            this._signatureText.maxChars = 15;
            var _loc_3:* = new Bitmap(GlobalClass.getBitmapData(BitmapDataConst.AlphaBMD));
            this._signatureText.setStyle("upSkin", _loc_3);
            this._signatureText.setStyle("disabledSkin", _loc_3);
            this._signatureText.setStyle("focusRectSkin", _loc_3);
            this._changeBtn = UIFactory.gLoadingButton(ImagesConst.RoleHalidomEBtn_upSkin, 26, 50, 58, 25, this._window.contentTopOf3DSprite);
            this._changeBtn.label = "";
            this._changeBtn2 = UIFactory.gLoadingButton(ImagesConst.RoleHalidomHBtn_upSkin, 26, 50, 58, 25, this._window.contentTopOf3DSprite);
            this._changeBtn2.label = "";
            this._medalPanel = UICompomentPool.getUICompoment(MedalBigIcon);
            this._medalPanel.isOpenWin = false;
            this._medalPanel.move(395, 77);
            this._window.contentTopOf3DSprite.addChild(this._medalPanel);
            this._changeBtn.configEventListener(MouseEvent.CLICK, this.onChHd);
            this._changeBtn2.configEventListener(MouseEvent.CLICK, this.onChHd);
            if (RoleHalidomPanel.levelEnougth())
            {
                this._changeBtn.visible = false;
                this._changeBtn2.visible = true;
            }
            else
            {
                this._changeBtn.visible = false;
                this._changeBtn2.visible = false;
            }
            return;
        }// end function

        private function addQQVipIcon(event:Event = null) : void
        {
            var _loc_2:String = "";
            if (this._sLookPlayerInfo.miniPlayer.proxyLevel)
            {
                _loc_2 = PlatformTencentUtil.getQQVipIconUrl(this._sLookPlayerInfo.miniPlayer.proxyLevel);
            }
            this._qqIcon.imgUrl = _loc_2;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            Global.stage.removeEventListener(MouseEvent.MOUSE_DOWN, this.startTurn);
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.stopTurn);
            if (this._qqIcon)
            {
                this._qqIcon.dispose(param1);
                this._qqIcon = null;
            }
            if (this._qqSpr)
            {
                this._qqSpr.dispose(param1);
                this._qqSpr = null;
            }
            this._changeBtn = null;
            this._changeBtn2 = null;
            if (this._halidomSp)
            {
                this._halidomSp.dispose(param1);
                this._halidomSp = null;
            }
            this._haliShow = false;
            this._guildTxt.dispose(param1);
            this._levelAndNameAndCarrar.dispose(param1);
            this._equipPanel.dispose(param1);
            this._leftBtn.dispose(param1);
            this._rightBtn.dispose(param1);
            this._vipIcon.dispose(param1);
            this._signatureTextBox.dispose(param1);
            this._signatureText.dispose(param1);
            this._3dRotationSp.dispose(param1);
            this._3dRotationBm.dispose(param1);
            this._bg.dispose(param1);
            this._playerTitle.dispose(param1);
            this._medalPanel.dispose(param1);
            this._3dRotationSp = null;
            this._3dRotationBm = null;
            this._guildTxt = null;
            this._levelAndNameAndCarrar = null;
            this._equipPanel = null;
            this._leftBtn = null;
            this._rightBtn = null;
            this._medalPanel = null;
            this._vipIcon = null;
            this._signatureTextBox = null;
            this._signatureText = null;
            this._bg = null;
            this._playerTitle = null;
            this.remove3d();
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            this.stopTurning();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.stopTurning);
            super.disposeImpl(param1);
            return;
        }// end function

        private function getMedalData() : MedalData
        {
            var _loc_3:TMedal = null;
            var _loc_4:int = 0;
            var _loc_1:* = new MedalData();
            var _loc_2:* = new Dictionary();
            for each (_loc_4 in this._sLookPlayerInfo.medals)
            {
                
                _loc_3 = MedalConfig.instance.getTmedalByCode(_loc_4);
                _loc_2[_loc_4] = _loc_3;
            }
            _loc_1.totalMedalDic = _loc_2;
            return _loc_1;
        }// end function

        private function add2d() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.add3DRole();
            if (this._img2d && this._rect3d)
            {
                this._rect3d.removeImg(this._img2d);
            }
            this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, 490, 546), false);
            this._rect3d.addImg(this._img2d);
            this.updateRoleModel();
            this.showHaliDom(this._haliShow);
            return;
        }// end function

        private function startTurn(event:MouseEvent) : void
        {
            this._startX = this.mouseX;
            this._3dRotationSp.configEventListener(MouseEvent.MOUSE_MOVE, this.turning);
            return;
        }// end function

        private function stopTurn(event:MouseEvent) : void
        {
            this._3dRotationSp.removeEventListener(MouseEvent.MOUSE_MOVE, this.turning);
            return;
        }// end function

        private function turning(event:MouseEvent) : void
        {
            this._endX = this.mouseX;
            this._roleModelPlayer.rotationY = this._roleModelPlayer.rotationY - (this._endX - this._startX) / 2;
            this._startX = this._endX;
            return;
        }// end function

        protected function onClickTurnBtn(event:MouseEvent) : void
        {
            if (this._roleModelPlayer)
            {
                if (event.currentTarget == this._leftBtn)
                {
                    this.turnValue = 2;
                }
                if (event.currentTarget == this._rightBtn)
                {
                    this.turnValue = -2;
                }
                this.start();
            }
            return;
        }// end function

        protected function stopTurning(event:MouseEvent = null) : void
        {
            if (this._frameTimer)
            {
                this._frameTimer.stop();
            }
            return;
        }// end function

        protected function onTurning(param1:FrameTimer) : void
        {
            if (this._roleModelPlayer)
            {
                this._roleModelPlayer.rotationY = this._roleModelPlayer.rotationY + this.turnValue;
            }
            return;
        }// end function

        private function start() : void
        {
            if (!this._frameTimer)
            {
                this._frameTimer = new FrameTimer(1, int.MAX_VALUE, true);
                this._frameTimer.addListener(TimerType.ENTERFRAME, this.onTurning);
            }
            this._frameTimer.start();
            return;
        }// end function

        private function onChHd(event:MouseEvent) : void
        {
            var _loc_2:Boolean = false;
            if (this._changeBtn2 == event.currentTarget)
            {
                _loc_2 = true;
            }
            if (this._haliShow != _loc_2)
            {
                this._haliShow = _loc_2;
                this.showHaliDom(this._haliShow);
            }
            return;
        }// end function

        private function showHaliDom(param1:Boolean) : void
        {
            this._equipPanel.visible = !param1;
            this._leftBtn.visible = !param1;
            this._rightBtn.visible = !param1;
            this._signatureTextBox.visible = !param1;
            this._signatureText.visible = !param1;
            this._medalPanel.visible = !param1;
            this._changeBtn.visible = param1;
            this._changeBtn2.visible = !param1;
            if (this._img2d)
            {
                this._img2d.visible = !param1;
            }
            if (param1)
            {
                this._playerTitle.x = 180;
                if (this._halidomSp == null)
                {
                    this._halidomSp = UIFactory.getUICompoment(LookPlayerHalidomPanel, 7, 60, this._window.contentTopOf3DSprite);
                }
                this._halidomSp.data = this._sLookPlayerInfo;
                this._halidomSp.init3DMd(this._rect3d);
            }
            else
            {
                this._playerTitle.x = 135;
                if (this._halidomSp)
                {
                    this._halidomSp.dispose();
                    this._halidomSp = null;
                }
            }
            return;
        }// end function

        private function createTextBox(param1:int = 1) : TextBox
        {
            var _loc_3:TextBox = null;
            var _loc_2:* = GlobalStyle.textFormatHuang;
            _loc_2.align = AlignMode.CENTER;
            _loc_3 = UICompomentPool.getUICompoment(TextBox);
            _loc_3.createDisposedChildren();
            _loc_3.setbgStlye(ImagesConst.PanelBg, _loc_2);
            _loc_3.textField.y = 1;
            _loc_3.textFieldHeight = 15;
            _loc_3.textFieldWidth = 80;
            _loc_3.bgHeight = 23;
            _loc_3.bgWidth = 137;
            _loc_3.x = (param1 - 1) * 141 + 16;
            _loc_3.y = 90;
            this._window.contentTopOf3DSprite.addChild(_loc_3);
            return _loc_3;
        }// end function

        public function updateInfo(param1:SLookPlayerInfo) : void
        {
            var _loc_2:Array = null;
            this._sLookPlayerInfo = param1;
            this._bg.imgUrl = ImagesConst.playerModule_RoleBg;
            this._equipPanel.updateAllEquip(this._sLookPlayerInfo.playerItems, this._sLookPlayerInfo.jewels);
            this._signatureText.text = this._sLookPlayerInfo.miniPlayer.signature ? (this._sLookPlayerInfo.miniPlayer.signature) : (Language.getString(30144));
            this._levelAndNameAndCarrar.htmlText = this._sLookPlayerInfo.miniPlayer.level + Language.getString(35333) + this._sLookPlayerInfo.miniPlayer.name + " · <font color=\'#d618dd\'>" + this.getCareer(this._sLookPlayerInfo.miniPlayer.career) + "</font>";
            if (this._sLookPlayerInfo.titleName)
            {
                this._playerTitle.text = this._sLookPlayerInfo.titleName;
            }
            else
            {
                this._playerTitle.text = Language.getString(35334);
            }
            if (this._sLookPlayerInfo.guildName)
            {
                _loc_2 = this._sLookPlayerInfo.guildName.split("#");
                this._guildTxt.htmlText = "<font color=\'#f8eacd\'>" + _loc_2[0] + " · " + GameDefConfig.instance.getItem("EGuildPostion", int(_loc_2[1])).text + "</font>";
            }
            else
            {
                this._guildTxt.text = "";
            }
            if (this._sLookPlayerInfo.miniPlayer.VIP > 0)
            {
                this._vipIcon.visible = true;
                this._vipIcon.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(this._sLookPlayerInfo.miniPlayer.VIP, 2);
            }
            else
            {
                this._vipIcon.visible = false;
                this._vipIcon.imgUrl = "";
            }
            this._medalPanel.medal = this.getHeightestMedal();
            this._medalPanel.toolTipData = this.getMedalData();
            if (PlatformConst.isQQ() && PlatformTencentUtil.isBlueEnter())
            {
                this.addQQVipIcon();
            }
            return;
        }// end function

        private function getHeightestMedal() : TMedal
        {
            var _loc_2:TMedal = null;
            var _loc_1:* = this._sLookPlayerInfo.medals;
            if (_loc_1)
            {
                _loc_1.sort(this.medalSort);
                _loc_2 = MedalConfig.instance.getTmedalByCode(_loc_1[(_loc_1.length - 1)]);
            }
            return _loc_2;
        }// end function

        private function medalSort(param1:int, param2:int) : int
        {
            if (param1 < param2)
            {
                return -1;
            }
            return 1;
        }// end function

        private function getCareer(param1:int) : String
        {
            return GameDefConfig.instance.getCarrer(param1);
        }// end function

        protected function add3DRole() : void
        {
            if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(11, 38, 490, 546), this._window);
            }
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        protected function updateRoleModel() : void
        {
            var _loc_1:ItemEquipInfo = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:SPlayerItem = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Boolean = false;
            var _loc_12:Boolean = false;
            var _loc_13:Boolean = false;
            if (this._rect3d)
            {
                _loc_6 = this._sLookPlayerInfo.miniPlayer.VIP;
                for each (_loc_7 in this._sLookPlayerInfo.playerItems)
                {
                    
                    _loc_1 = ItemConfig.instance.getConfig(_loc_7.itemCode) as ItemEquipInfo;
                    if (_loc_1.type == EEquip._EEquipWeaponFashion)
                    {
                        _loc_3 = int(_loc_1.modelId);
                        continue;
                    }
                    if (_loc_2 == 0 && _loc_1.type == EEquip._EEquipClothes)
                    {
                        _loc_2 = int(_loc_1.modelId);
                        continue;
                    }
                    if (_loc_3 == 0 && _loc_1.type == EEquip._EEquipWeapon)
                    {
                        _loc_3 = int(_loc_1.modelId);
                        continue;
                    }
                    if (_loc_1.type == EEquip._EEquipHeadwear)
                    {
                        _loc_5 = int(_loc_1.modelId);
                    }
                }
                _loc_8 = this.getClothesModelId();
                _loc_9 = this.getWingModelId();
                _loc_10 = this.getWeaponModelId();
                if (_loc_8 > 0)
                {
                    _loc_2 = _loc_8;
                }
                if (_loc_9 > 0)
                {
                    _loc_4 = _loc_9;
                }
                if (_loc_10 > 0)
                {
                    _loc_3 = _loc_10;
                }
                if (this._roleModelPlayer == null)
                {
                    this._roleModelPlayer = FrObjectPool.getObject(RoleModelPlayer, this);
                }
                _loc_11 = this._sLookPlayerInfo.clothesCode > 10000;
                _loc_12 = this._sLookPlayerInfo.wingCode > 10000;
                _loc_13 = this._sLookPlayerInfo.weaponCode > 10000;
                this._roleModelPlayer.updateIsShowEffect(_loc_13, _loc_11, _loc_12);
                this._roleModelPlayer.updateInfo(this._sLookPlayerInfo.miniPlayer.career, this._sLookPlayerInfo.miniPlayer.sex, _loc_2, _loc_3, _loc_5, _loc_4, _loc_6);
                this._roleModelPlayer.scaleAll = 2.2;
                this._roleModelPlayer.setRenderList(this._rect3d.renderList);
                this._roleModelPlayer.useLight();
                this._roleModelPlayer.rotationY = 0;
                this._rect3d.addObject3d(this._roleModelPlayer, 243, 465);
                Global.stage.addEventListener(MouseEvent.MOUSE_DOWN, this.startTurn);
                Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopTurn);
            }
            return;
        }// end function

        private function getClothesModelId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:TMountConfig = null;
            if (this._sLookPlayerInfo.clothesCode > 10000)
            {
                _loc_2 = ItemConfig.instance.getConfig(this._sLookPlayerInfo.clothesCode) as ItemEquipInfo;
                _loc_1 = _loc_2 ? (_loc_2.modelId) : (0);
            }
            else
            {
                _loc_3 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypeClothes, this._sLookPlayerInfo.clothesCode);
                _loc_1 = _loc_3 ? (_loc_3.modelId) : (0);
            }
            return _loc_1;
        }// end function

        private function getWingModelId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:TMountConfig = null;
            if (this._sLookPlayerInfo.wingCode > 10000)
            {
                _loc_2 = ItemConfig.instance.getConfig(this._sLookPlayerInfo.wingCode) as ItemEquipInfo;
                _loc_1 = _loc_2 ? (_loc_2.modelId) : (0);
            }
            else
            {
                _loc_3 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypeWing, this._sLookPlayerInfo.wingCode);
                _loc_1 = _loc_3 ? (_loc_3.modelId) : (0);
            }
            return _loc_1;
        }// end function

        private function getWeaponModelId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:TMountConfig = null;
            if (this._sLookPlayerInfo.weaponCode > 10000)
            {
                _loc_2 = ItemConfig.instance.getConfig(this._sLookPlayerInfo.weaponCode) as ItemEquipInfo;
                _loc_1 = _loc_2 ? (_loc_2.modelId) : (0);
            }
            else
            {
                _loc_3 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypeWing, this._sLookPlayerInfo.weaponCode);
                _loc_1 = _loc_3 ? (_loc_3.modelId) : (0);
            }
            return _loc_1;
        }// end function

        private function remove3d() : void
        {
            if (this._rect3d)
            {
                this._rect3d.removeImg(this._img2d);
                this._rect3d.disposeObj3d(this._roleModelPlayer);
                this._roleModelPlayer = null;
            }
            return;
        }// end function

    }
}
